package com.fyx.timedTask;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fyx.config.*;
import com.fyx.entity.*;
import com.fyx.mapper.BrokeInfoMapper;
import com.fyx.mapper.PlayerNumberMapper;
import com.fyx.mapper.RoomsUserInfoMapper;
import com.fyx.mapper.SysDictDetailMapper;
import com.fyx.until.DateUtil;
import com.fyx.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;


@Slf4j
@Component(value="RoomsDateTask")
public class RoomsDateTask {

    @Resource(name = SecondaryMongoConfig.MONGO_TEMPLATE)
    private MongoTemplate secondaryMongoTemplate;

    @Resource(name = FiveMongoConfig.MONGO_TEMPLATE)
    private MongoTemplate fiveMongoTemplate;

    @Resource(name = SixthMongoConfig.MONGO_TEMPLATE)
    private MongoTemplate sixthMongoTemplate;

    @Resource(name = NinethMongoConfig.MONGO_TEMPLATE)
    private MongoTemplate ninethMongoTemplate;

    @Resource(name = TenthMongoConfig.MONGO_TEMPLATE)
    private MongoTemplate tenthMongoTemplate;

    @Autowired
    private MongoTemplate mongoTemplate;

    @Autowired
    SysDictDetailMapper sysDictDetailMapper;

    @Autowired
    RoomsUserInfoMapper roomsUserInfoMapper;

    @Autowired
    private PlayerNumberMapper playerNumberMapper;

    @Autowired
    private BrokeInfoMapper brokeInfoMapper;

    public void run(){
        recordByBroke();
        log.info("运营数据任务rooms：开始执行=======================");
        record();
        log.info("运营数据任务rooms：执行完毕=======================");

//        for(Long beginTime = 1675180800l;beginTime<=1677340800;beginTime+=86400){
//            record(beginTime);
//            recordByBroke(beginTime);
//        }

    }

//    public void  eeeee(String tabelStrig,long beginTime,int i){
//        String collectionName = "tally_rec_"+tabelStrig;
//        QueryWrapper<SysDictDetail> wrapper1 = new QueryWrapper<>();
//        wrapper1.eq("dict_id", 21);
//        List<SysDictDetail> list1 = sysDictDetailMapper.selectList(wrapper1);
//        wrapper1 = new QueryWrapper<>();
//        wrapper1.eq("dict_id", 22);
//        List<SysDictDetail> list2 = sysDictDetailMapper.selectList(wrapper1);
//        RoomsUserInfo roomsUserInfo=new RoomsUserInfo();
//        for (SysDictDetail sysDictDetail : list1) {
//            if(!sysDictDetail.getValue().equals("5")){
//                for (SysDictDetail sysDictDetail2 : list2) {
//                    Criteria criteria = new Criteria();
//                    criteria.and("time").gte(beginTime).lte(beginTime+86400);
//                    criteria.and("gameid").is(Integer.parseInt(sysDictDetail.getValue()));
//                    criteria.and("placeid").is(Integer.parseInt(sysDictDetail2.getValue()));
//                    criteria.and("is_robot").is(true);
//                    Aggregation aggregation = Aggregation.newAggregation(
//                            Aggregation.match(criteria),
//                            Aggregation.group().sum("num").as("unix_time")
//                    );
//                     AggregationResults<TallyRecEntity>   ar;
//                     if(i==1) {
//                         ar = secondaryMongoTemplate.aggregate(aggregation, collectionName, TallyRecEntity.class);
//                     }else {
//                         ar = sixthMongoTemplate.aggregate(aggregation, collectionName, TallyRecEntity.class);
//                     }
//                    List<TallyRecEntity> list = ar.getMappedResults();
////                    System.out.println("criteria is ==============="+new Query().addCriteria(criteria));
////                    System.out.println("list is ==============="+list);
//                    if (list.size() > 0) {
//                        if(sysDictDetail.getValue().equals("1")){
//                            if(sysDictDetail2.getValue().equals("1")) {
//                                roomsUserInfo.setMoney1( list.get(0).getUnix_time());
//                            }else  if(sysDictDetail2.getValue().equals("2")) {
//                                roomsUserInfo.setMoney2(list.get(0).getUnix_time());
//                            }else  if(sysDictDetail2.getValue().equals("3")) {
//                                roomsUserInfo.setMoney3(list.get(0).getUnix_time());
//                            }else  if(sysDictDetail2.getValue().equals("4")) {
//                                roomsUserInfo.setMoney4(list.get(0).getUnix_time());
//                            }
//                        }if(sysDictDetail.getValue().equals("2")){
//                            if(sysDictDetail2.getValue().equals("1")) {
//                                roomsUserInfo.setMoney6(list.get(0).getUnix_time());
//                            }else  if(sysDictDetail2.getValue().equals("2")) {
//                                roomsUserInfo.setMoney7(list.get(0).getUnix_time());
//                            }else  if(sysDictDetail2.getValue().equals("3")) {
//                                roomsUserInfo.setMoney8(list.get(0).getUnix_time());
//                            }else  if(sysDictDetail2.getValue().equals("4")) {
//                                roomsUserInfo.setMoney9(list.get(0).getUnix_time());
//                            }
//                        }if(sysDictDetail.getValue().equals("3")){
//                            if(sysDictDetail2.getValue().equals("1")) {
//                                roomsUserInfo.setMoney11(list.get(0).getUnix_time());
//                            }else  if(sysDictDetail2.getValue().equals("2")) {
//                                roomsUserInfo.setMoney12(list.get(0).getUnix_time());
//                            }else  if(sysDictDetail2.getValue().equals("3")) {
//                                roomsUserInfo.setMoney13(list.get(0).getUnix_time());
//                            }else  if(sysDictDetail2.getValue().equals("4")) {
//                                roomsUserInfo.setMoney14(list.get(0).getUnix_time());
//                            }
//                        }if(sysDictDetail.getValue().equals("4")){
//                            if(sysDictDetail2.getValue().equals("1")) {
//                                roomsUserInfo.setMoney16(list.get(0).getUnix_time());
//                            }else  if(sysDictDetail2.getValue().equals("2")) {
//                                roomsUserInfo.setMoney17(list.get(0).getUnix_time());
//                            }else  if(sysDictDetail2.getValue().equals("3")) {
//                                roomsUserInfo.setMoney18(list.get(0).getUnix_time());
//                            }else  if(sysDictDetail2.getValue().equals("4")) {
//                                roomsUserInfo.setMoney19(list.get(0).getUnix_time());
//                            }
//                        }if(sysDictDetail.getValue().equals("6")){
//                            if(sysDictDetail2.getValue().equals("1")) {
//                                roomsUserInfo.setMoney20(list.get(0).getUnix_time());
//                            }else  if(sysDictDetail2.getValue().equals("2")) {
//                                roomsUserInfo.setMoney21(list.get(0).getUnix_time());
//                            }else  if(sysDictDetail2.getValue().equals("3")) {
//                                roomsUserInfo.setMoney22(list.get(0).getUnix_time());
//                            }else  if(sysDictDetail2.getValue().equals("4")) {
//                                roomsUserInfo.setMoney23(list.get(0).getUnix_time());
//                            }
//                        }if(sysDictDetail.getValue().equals("9")){
//                            if(sysDictDetail2.getValue().equals("1")) {
//                                roomsUserInfo.setMoney33(list.get(0).getUnix_time());
//                            }else  if(sysDictDetail2.getValue().equals("2")) {
//                                roomsUserInfo.setMoney34(list.get(0).getUnix_time());
//                            }else  if(sysDictDetail2.getValue().equals("3")) {
//                                roomsUserInfo.setMoney35(list.get(0).getUnix_time());
//                            }else  if(sysDictDetail2.getValue().equals("4")) {
//                                roomsUserInfo.setMoney36(list.get(0).getUnix_time());
//                            }
//                        }
//                    }
//                }
//             }
//        }
//        if(i==1){
//            QueryWrapper<RoomsUserInfo> wrapper3 = new QueryWrapper<>();
//            wrapper3.eq("create_time", beginTime);
//            wrapper3.eq("channel","total");
//            RoomsUserInfo roomsUserInfo1=roomsUserInfoMapper.selectOne(wrapper3);
//            roomsUserInfo1.setMoney1(roomsUserInfo.getMoney1());
//            roomsUserInfo1.setMoney2(roomsUserInfo.getMoney2());
//            roomsUserInfo1.setMoney3(roomsUserInfo.getMoney3());
//            roomsUserInfo1.setMoney4(roomsUserInfo.getMoney4());
//            roomsUserInfo1.setMoney6(roomsUserInfo.getMoney6());
//            roomsUserInfo1.setMoney7(roomsUserInfo.getMoney7());
//            roomsUserInfo1.setMoney8(roomsUserInfo.getMoney8());
//            roomsUserInfo1.setMoney9(roomsUserInfo.getMoney9());
//            roomsUserInfo1.setMoney11(roomsUserInfo.getMoney11());
//            roomsUserInfo1.setMoney12(roomsUserInfo.getMoney12());
//            roomsUserInfo1.setMoney13(roomsUserInfo.getMoney13());
//            roomsUserInfo1.setMoney14(roomsUserInfo.getMoney14());
//            roomsUserInfo1.setMoney16(roomsUserInfo.getMoney16());
//            roomsUserInfo1.setMoney17(roomsUserInfo.getMoney17());
//            roomsUserInfo1.setMoney18(roomsUserInfo.getMoney18());
//            roomsUserInfo1.setMoney19(roomsUserInfo.getMoney19());
//            roomsUserInfo1.setMoney20(roomsUserInfo.getMoney20());
//            roomsUserInfo1.setMoney21(roomsUserInfo.getMoney21());
//            roomsUserInfo1.setMoney22(roomsUserInfo.getMoney22());
//            roomsUserInfo1.setMoney23(roomsUserInfo.getMoney23());
//            roomsUserInfoMapper.update(roomsUserInfo1,wrapper3);
//        }else {
//            QueryWrapper<RoomsUserInfo> wrapper3 = new QueryWrapper<>();
//            wrapper3.eq("create_time", beginTime);
//            wrapper3.eq("channel","totalcl");
//            RoomsUserInfo roomsUserInfo1=roomsUserInfoMapper.selectOne(wrapper3);
//            roomsUserInfo1.setMoney33(roomsUserInfo.getMoney33());
//            roomsUserInfo1.setMoney34(roomsUserInfo.getMoney34());
//            roomsUserInfo1.setMoney35(roomsUserInfo.getMoney35());
//            roomsUserInfo1.setMoney36(roomsUserInfo.getMoney36());
//            roomsUserInfoMapper.update(roomsUserInfo1,wrapper3);
//        }
//    }
    public void record() {
        String collectionName = "tally_rec_";
        String gameRoundName = "game_round_rec_";
        String gameName="login_game_rec_";
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM");
        Long beginTime = DateUtil.getDayBegin().getTime() / 1000;
        String dateStr = ft.format(new Date()).replace("-", "").trim();
        Long nowTime=new Date().getTime()/1000;
        if(nowTime==beginTime){
            beginTime=DateUtil.getBeginDayOfYesterday().getTime()/1000;
            if(!DateUtil.timeStamp2Date(beginTime+"","yyyyMM").equals(DateUtil.timeStamp2Date(nowTime+"","yyyyMM"))){
                dateStr =DateUtil.timeStamp2Date(beginTime+"","yyyyMM");
            }
        }
        Long endTime = beginTime+86400;
        collectionName = collectionName + dateStr;
        gameRoundName = gameRoundName + dateStr;
        gameName = gameName + dateStr;
        Criteria criteria;
        QueryWrapper<SysDictDetail> wrapper1 = new QueryWrapper<>();
        wrapper1.eq("dict_id", 21);
        List<SysDictDetail> list1 = sysDictDetailMapper.selectList(wrapper1);
        wrapper1 = new QueryWrapper<>();
        wrapper1.eq("dict_id", 22);
        List<SysDictDetail> list2 = sysDictDetailMapper.selectList(wrapper1);
        String str = "";
        String theValue="";
        Aggregation aggregation;
        AggregationResults<TallyRecEntity> ar;
        List<TallyRecEntity> list;
        QueryWrapper<SysDictDetail> wrapper = new QueryWrapper<>();
        wrapper.eq("dict_id", 16);
        wrapper.le("dict_sort", 988);
        wrapper.orderByDesc("dict_sort");
        List<SysDictDetail> list5 = sysDictDetailMapper.selectList(wrapper);
        if (list5.size() > 0) {
            for (SysDictDetail sysDictDetail3 : list5) {
                    str = "";
                    theValue = "";
                    RoomsUserInfo roomsUserInfo = new RoomsUserInfo();
                    for (SysDictDetail sysDictDetail : list1) {
                        for (SysDictDetail sysDictDetail2 : list2) {
                            theValue += "\"a" + sysDictDetail.getValue() + "0" + sysDictDetail2.getValue() + "\":{";
                            criteria = new Criteria();
                            criteria.and("unix_time").gte(beginTime).lte(endTime);
                            criteria.and("gameType").is(Integer.parseInt(sysDictDetail.getValue() + "0" + sysDictDetail2.getValue()));
                            if (sysDictDetail3.getDictSort() != null && sysDictDetail3.getDictSort() == 987) {
                                if (sysDictDetail.getValue().equals("h5hzmjxl_wechat") || sysDictDetail.getValue().equals("h5hzmjxl_qq") || sysDictDetail.getValue().equals("h5gdmjxl_wechat") || sysDictDetail.getValue().equals("h5hcmjxl_wechat")) {

                                    criteria.and("channel").is(sysDictDetail3.getValue());
                                    criteria.and("invite_channel").is("");
                                } else {
                                    criteria.and("invite_channel").is(sysDictDetail3.getValue());
                                }
                            } else if (sysDictDetail3.getDictSort() != null) {
                                if (sysDictDetail3.getDictSort() == 900 || sysDictDetail3.getDictSort() == 910||sysDictDetail.getDictSort()==920) {
                                    criteria.and("channel").regex(sysDictDetail3.getValue().split("_")[0]);
                                } else {
                                    criteria.and("channel").is(sysDictDetail3.getValue());
                                }
                            }
                            aggregation = Aggregation.newAggregation(
                                    Aggregation.match(criteria),
                                    Aggregation.group("id").count().as("ioType"),
                                    Aggregation.group("id").count().as("ioType")
                            );
                            if ( sysDictDetail3.getValue().indexOf("cl_") > 0) {
                                ar = sixthMongoTemplate.aggregate(aggregation, gameName, TallyRecEntity.class);
                            }else if ( sysDictDetail3.getValue().indexOf("gdmj") ==0) {
                                ar = tenthMongoTemplate.aggregate(aggregation, gameName, TallyRecEntity.class);
                            } else {
                                ar = secondaryMongoTemplate.aggregate(aggregation, gameName, TallyRecEntity.class);
                            }
                            list = ar.getMappedResults();
                            if (list.size() > 0) {
                                str = str + "@" + sysDictDetail.getValue() + "0" + sysDictDetail2.getValue() + "/" + list.get(0).getIoType();
                                theValue += "\"active\":" + list.get(0).getIoType() + ",";
                            } else {
                                str = str + "@" + sysDictDetail.getValue() + "0" + sysDictDetail2.getValue() + "/0";
                                theValue += "\"active\":0,";
                            }
                            aggregation = Aggregation.newAggregation(
                                    Aggregation.match(criteria),
                                    Aggregation.group("roomid").count().as("ioType"),
                                    Aggregation.group("roomid").count().as("ioType")
                            );
                            if ( sysDictDetail3.getValue().indexOf("cl_") > 0) {
                                ar = sixthMongoTemplate.aggregate(aggregation, gameName, TallyRecEntity.class);
                            } else if ( sysDictDetail3.getValue().indexOf("gdmj") ==0) {
                                ar = tenthMongoTemplate.aggregate(aggregation, gameName, TallyRecEntity.class);
                            }
                            else {
                                ar = secondaryMongoTemplate.aggregate(aggregation, gameName, TallyRecEntity.class);
                            }
                            list = ar.getMappedResults();
                            if (list.size() > 0) {
                                str = str + "/" + list.get(0).getIoType();
                                theValue += "\"number\":" + list.get(0).getIoType() + ",";
                                roomsUserInfo.setNumber(roomsUserInfo.getNumber() + list.get(0).getIoType());
                            } else {
                                str = str + "/0";
                                theValue += "\"number\":0,";
                            }
                            str = str + "/0";
                            theValue += "\"money\":0,";
                            str = str + "/0";
                            theValue += "\"avgTime\":0},";
                        }
                    }

                    theValue = "{" + theValue.substring(0, theValue.length() - 1) + "}";
                    String[] strArray = str.split("@");
                   roomsUserInfo.setTheValue(theValue);
                   if (sysDictDetail3.getDictSort() != null && sysDictDetail3.getDictSort() == 987) {
                            if (sysDictDetail3.getValue().equals("qq_share") || sysDictDetail3.getValue().equals("h5hzmjxl_qq")) {
                                roomsUserInfo.setTheFather("h5hzmjxl_qq");
                            } else if (sysDictDetail3.getValue().indexOf("gdmj") > -1) {
                                roomsUserInfo.setTheFather("h5gdmjxl_wechat");
                            } else if (sysDictDetail3.getValue().indexOf("hcmj") > -1) {
                                roomsUserInfo.setTheFather("h5hcmjxl_wechat");
                            } else {
                                roomsUserInfo.setTheFather("h5hzmjxl_wechat");
                            }
                   } else if (sysDictDetail3.getDictSort() == 900) {
                            roomsUserInfo.setTheFather("total");
                        } else if (sysDictDetail3.getDictSort() == 910) {
                            roomsUserInfo.setTheFather("totalcl");
                   } else if(sysDictDetail3.getDictSort()==920){
                       roomsUserInfo.setTheFather("totalapp");
                   }else {
                            if (sysDictDetail3.getValue().equals("h5zhsmjcl_wechat")) {
                                roomsUserInfo.setTheFather("zsmjxl_total");
                            }else if(sysDictDetail3.getValue().indexOf("gdmj")==0){
                                roomsUserInfo.setTheFather(sysDictDetail3.getValue().split("_")[0] + "_app_total");
                            } else {
                                roomsUserInfo.setTheFather(sysDictDetail3.getValue().split("_")[0].replace("h5", "") + "_total");
                            }
                   }

                    criteria = new Criteria();
                    criteria.and("unix_time").gte(beginTime).lte(endTime);
                    if (sysDictDetail3.getDictSort() != null && sysDictDetail3.getDictSort() == 987) {
                        if (sysDictDetail3.getValue().equals("h5hzmjxl_wechat") || sysDictDetail3.getValue().equals("h5hzmjxl_qq") || sysDictDetail3.getValue().equals("h5gdmjxl_wechat") || sysDictDetail3.getValue().equals("h5hcmjxl_wechat")) {
                            criteria.and("channel").is(sysDictDetail3.getValue());
                            criteria.and("invite_channel").is("");
                        } else {
                            criteria.and("invite_channel").is(sysDictDetail3.getValue());
                        }
                    } else if (sysDictDetail3.getDictSort() != null) {
                        if (sysDictDetail3.getDictSort() == 900 || sysDictDetail3.getDictSort() == 910||sysDictDetail3.getDictSort()==920) {
                            criteria.and("channel").regex(sysDictDetail3.getValue().split("_")[0]);
                        } else {
                            criteria.and("channel").is(sysDictDetail3.getValue());
                        }
                    }
                    aggregation = Aggregation.newAggregation(
                            Aggregation.match(criteria),
                            Aggregation.group("id").count().as("ioType"),
                            Aggregation.group("id").count().as("ioType")
                    );
                    if (sysDictDetail3.getValue().equals("totalcl") || sysDictDetail3.getValue().indexOf("cl_") > 0) {
                        ar = sixthMongoTemplate.aggregate(aggregation, gameName, TallyRecEntity.class);
                    } else if (sysDictDetail3.getValue().equals("totalapp") || sysDictDetail3.getValue().indexOf("gdmj") == 0) {
                        ar = tenthMongoTemplate.aggregate(aggregation, gameName, TallyRecEntity.class);
                     }else {
                        ar = secondaryMongoTemplate.aggregate(aggregation, gameName, TallyRecEntity.class);
                    }
                    list = ar.getMappedResults();
                    if (list.size() > 0) {
                        roomsUserInfo.setActive(list.get(0).getIoType());
                    }
                    roomsUserInfo.setChannel(sysDictDetail3.getValue());
                    roomsUserInfo.setCreateTime(beginTime);
                    QueryWrapper<RoomsUserInfo> wrapper3 = new QueryWrapper<>();
                    wrapper3.eq("create_time", beginTime);
                    wrapper3.eq("channel", roomsUserInfo.getChannel());
                    if (StringUtils.isNotEmpty(roomsUserInfo.getTheFather())) {
                        wrapper3.eq("the_father", roomsUserInfo.getTheFather());
                    }
                    RoomsUserInfo roomsUserInfo1 = roomsUserInfoMapper.selectOne(wrapper3);
                    if (roomsUserInfo1 == null) {
                        roomsUserInfo1 = new RoomsUserInfo();
                    }
                    for (int j = 1; j < strArray.length; j++) {
                        int res=Integer.parseInt(strArray[j].split("/")[0]);
                        if (res==101) {
                            roomsUserInfo.setActive1(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber1(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney1(roomsUserInfo1.getMoney1() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime1(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res==102) {
                            roomsUserInfo.setActive2(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber2(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney2(roomsUserInfo1.getMoney2() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime2(Integer.valueOf(strArray[j].split("/")[4]));
                        } else  if (res==103) {
                            roomsUserInfo.setActive3(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber3(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney3(roomsUserInfo1.getMoney3() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime3(Integer.valueOf(strArray[j].split("/")[4]));
                        } else  if (res==104) {
                            roomsUserInfo.setActive4(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber4(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney4(roomsUserInfo1.getMoney4() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime4(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res==105) {
                            roomsUserInfo.setActive5(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber5(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney5(roomsUserInfo1.getMoney5() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime5(Integer.valueOf(strArray[j].split("/")[4]));
                        } else  if (res==201) {
                            roomsUserInfo.setActive6(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber6(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney6(roomsUserInfo1.getMoney6() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime6(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res==202) {
                            roomsUserInfo.setActive7(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber7(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney7(roomsUserInfo1.getMoney7() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime7(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res==203) {
                            roomsUserInfo.setActive8(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber8(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney8(roomsUserInfo1.getMoney8() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime8(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res==204) {
                            roomsUserInfo.setActive9(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber9(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney9(roomsUserInfo1.getMoney9() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime9(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res==205) {
                            roomsUserInfo.setActive10(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber10(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney10(roomsUserInfo1.getMoney10() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime10(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res==301) {
                            roomsUserInfo.setActive11(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber11(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney11(roomsUserInfo1.getMoney11() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime11(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res==302) {
                            roomsUserInfo.setActive12(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber12(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney12(roomsUserInfo1.getMoney12() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime12(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res==303) {
                            roomsUserInfo.setActive13(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber13(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney13(roomsUserInfo1.getMoney13() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime13(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res==304) {
                            roomsUserInfo.setActive14(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber14(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney14(roomsUserInfo1.getMoney14() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime14(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res==305) {
                            roomsUserInfo.setActive15(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber15(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney15(roomsUserInfo1.getMoney15() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime15(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res==401) {
                            roomsUserInfo.setActive16(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber16(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney16(roomsUserInfo1.getMoney16() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime16(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res==402) {
                            roomsUserInfo.setActive17(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber17(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney17(roomsUserInfo1.getMoney17() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime17(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res==403) {
                            roomsUserInfo.setActive18(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber18(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney18(roomsUserInfo1.getMoney18() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime18(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res==404) {
                            roomsUserInfo.setActive19(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber19(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney19(roomsUserInfo1.getMoney19() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime19(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res==601) {
                            roomsUserInfo.setActive20(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber20(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney20(roomsUserInfo1.getMoney20() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime20(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res==602) {
                            roomsUserInfo.setActive21(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber21(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney21(roomsUserInfo1.getMoney21() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime21(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res==603) {
                            roomsUserInfo.setActive22(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber22(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney22(roomsUserInfo1.getMoney22() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime22(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res==604) {
                            roomsUserInfo.setActive23(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber23(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney23(roomsUserInfo1.getMoney23() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime23(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res == 701) {
                            roomsUserInfo.setActive24(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber24(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney24(roomsUserInfo1.getMoney24() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime24(Integer.valueOf(strArray[j].split("/")[3]));
                        } else if (res == 702) {
                            roomsUserInfo.setActive25(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber25(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney25(roomsUserInfo1.getMoney25() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime25(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res == 703) {
                            roomsUserInfo.setActive26(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber26(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney26(roomsUserInfo1.getMoney26() + Long.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime26(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res == 704) {
                            roomsUserInfo.setActive27(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber27(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney27(roomsUserInfo1.getMoney27() + Long.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime27(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res == 801) {
                            roomsUserInfo.setActive28(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber28(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney28(roomsUserInfo1.getMoney28() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime28(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res == 802) {
                            roomsUserInfo.setActive29(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber29(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney29(roomsUserInfo1.getMoney29() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime29(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res == 803) {
                            roomsUserInfo.setActive30(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber30(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney30(roomsUserInfo1.getMoney30() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime30(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res == 804) {
                            roomsUserInfo.setActive31(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber31(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney31(roomsUserInfo1.getMoney31() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime31(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res == 805) {
                            roomsUserInfo.setActive32(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber32(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney32(roomsUserInfo1.getMoney32() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime32(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res == 901) {
                            roomsUserInfo.setActive33(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber33(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney33(roomsUserInfo1.getMoney33() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime33(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res == 902) {
                            roomsUserInfo.setActive34(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber34(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney34(roomsUserInfo1.getMoney34() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime34(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res == 903) {
                            roomsUserInfo.setActive35(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber35(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney35(roomsUserInfo1.getMoney35() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime35(Integer.valueOf(strArray[j].split("/")[4]));
                        } else if (res == 904) {
                            roomsUserInfo.setActive36(Integer.parseInt(strArray[j].split("/")[1]));
                            roomsUserInfo.setNumber36(Integer.parseInt(strArray[j].split("/")[2]));
                            roomsUserInfo.setMoney36(roomsUserInfo1.getMoney36() + Double.valueOf(strArray[j].split("/")[3]));
                            roomsUserInfo.setAvgTime36(Integer.valueOf(strArray[j].split("/")[4]));
                        }
                    }
                    if (roomsUserInfo1.getId() == null) {
                        roomsUserInfoMapper.insert(roomsUserInfo);
                    } else {
                        roomsUserInfoMapper.update(roomsUserInfo, wrapper3);
                    }
            }
        }
    }

    public void recordByBroke () {
            String collectionName = "recharge_rec_";
            SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM");
            String dateStr = ft.format(new Date()).replace("-", "").trim();
            Long beginTime = DateUtil.getDayBegin().getTime() / 1000;
            Long endTime = beginTime+86400;
            Long nowTime=new Date().getTime()/1000;
            if(nowTime==beginTime){
                beginTime=DateUtil.getBeginDayOfYesterday().getTime()/1000;
                if(!DateUtil.timeStamp2Date(beginTime+"","yyyyMM").equals(DateUtil.timeStamp2Date(nowTime+"","yyyyMM"))){
                    dateStr =DateUtil.timeStamp2Date(beginTime+"","yyyyMM");
                 }
            }
            collectionName = collectionName + dateStr;
            Criteria criteria = new Criteria();
            QueryWrapper<SysDictDetail> wrapper = new QueryWrapper<>();
            wrapper.eq("dict_id", 16);
            wrapper.le("dict_sort", 988).or().eq("dict_sort",999);
            wrapper.orderByDesc("dict_sort");
            List<SysDictDetail> list = sysDictDetailMapper.selectList(wrapper);
            wrapper = new QueryWrapper<>();
            wrapper.eq("dict_id", 21);
            List<SysDictDetail> gameList = sysDictDetailMapper.selectList(wrapper);
            wrapper = new QueryWrapper<>();
            wrapper.eq("dict_id", 22);
            List<SysDictDetail> placeList = sysDictDetailMapper.selectList(wrapper);
            if (list.size() > 0) {
                for (SysDictDetail sysDictDetail : list) {
                    BrokeInfo brokeInfo = new BrokeInfo();
                    criteria = new Criteria();
                    criteria.and("day").is(beginTime);
                    if (sysDictDetail.getDictSort()!=999){
                        if(sysDictDetail.getValue().indexOf("_total")>0) {
                            criteria.and("channel").regex(sysDictDetail.getValue().split("_")[0]);
                        }
                        else {
                            criteria.and("channel").is(sysDictDetail.getValue());
                        }
                    }
                    Aggregation aggregation = Aggregation.newAggregation(
                            Aggregation.match(criteria),
                            Aggregation.group().sum("brokes.101").as("broke")
                                    .sum("brokes.102").as("broke1")
                                    .sum("brokes.103").as("broke2")
                                    .sum("brokes.104").as("broke3")
                                    .sum("brokes.105").as("broke4")
                                    .sum("brokes.201").as("broke5")
                                    .sum("brokes.202").as("broke6")
                                    .sum("brokes.203").as("broke7")
                                    .sum("brokes.204").as("broke8")
                                    .sum("brokes.205").as("broke9")
                                    .sum("brokes.301").as("broke10")
                                    .sum("brokes.302").as("broke11")
                                    .sum("brokes.303").as("broke12")
                                    .sum("brokes.304").as("broke13")
                                    .sum("brokes.305").as("broke14")
                                    .sum("brokes.401").as("broke15")
                                    .sum("brokes.402").as("broke16")
                                    .sum("brokes.403").as("broke17")
                                    .sum("brokes.404").as("broke18")
                                    .sum("brokes.405").as("broke19")
                                    .sum("brokes.601").as("broke20")
                                    .sum("brokes.602").as("broke21")
                                    .sum("brokes.603").as("broke22")
                                    .sum("brokes.604").as("broke23")
                                    .sum("brokes.801").as("broke24")
                                    .sum("brokes.802").as("broke25")
                                    .sum("brokes.803").as("broke26")
                                    .sum("brokes.804").as("broke27")
                                    .sum("brokes.901").as("broke28")
                                    .sum("brokes.902").as("broke29")
                                    .sum("brokes.903").as("broke30")
                                    .sum("brokes.904").as("broke31")
                                    .sum("brokes.1001").as("broke32")
                                    .sum("brokes.1002").as("broke33")
                                    .sum("brokes.1003").as("broke34")
                                    .sum("brokes.1004").as("broke35")
                                    .sum("brokes.1301").as("broke36")
                                    .sum("brokes.1302").as("broke37")
                                    .sum("brokes.1303").as("broke38")
                                    .sum("brokes.1304").as("broke39")
                                    .sum("brokes.1201").as("broke40")
                                    .sum("brokes.1202").as("broke41")
                                    .sum("brokes.1203").as("broke42")
                                    .sum("brokes.1204").as("broke43")
                                    .sum("bankrupt_bouns.101").as("brokeBuy")
                                    .sum("bankrupt_bouns.102").as("brokeBuy1")
                                    .sum("bankrupt_bouns.103").as("brokeBuy2")
                                    .sum("bankrupt_bouns.104").as("brokeBuy3")
                                    .sum("bankrupt_bouns.105").as("brokeBuy4")
                                    .sum("bankrupt_bouns.201").as("brokeBuy5")
                                    .sum("bankrupt_bouns.202").as("brokeBuy6")
                                    .sum("bankrupt_bouns.203").as("brokeBuy7")
                                    .sum("bankrupt_bouns.204").as("brokeBuy8")
                                    .sum("bankrupt_bouns.205").as("brokeBuy9")
                                    .sum("bankrupt_bouns.301").as("brokeBuy10")
                                    .sum("bankrupt_bouns.302").as("brokeBuy11")
                                    .sum("bankrupt_bouns.303").as("brokeBuy12")
                                    .sum("bankrupt_bouns.304").as("brokeBuy13")
                                    .sum("bankrupt_bouns.305").as("brokeBuy14")
                                    .sum("bankrupt_bouns.401").as("brokeBuy15")
                                    .sum("bankrupt_bouns.402").as("brokeBuy16")
                                    .sum("bankrupt_bouns.403").as("brokeBuy17")
                                    .sum("bankrupt_bouns.404").as("brokeBuy18")
                                    .sum("bankrupt_bouns.405").as("brokeBuy19")
                                    .sum("bankrupt_bouns.601").as("brokeBuy20")
                                    .sum("bankrupt_bouns.602").as("brokeBuy21")
                                    .sum("bankrupt_bouns.603").as("brokeBuy22")
                                    .sum("bankrupt_bouns.604").as("brokeBuy23")
                                    .sum("bankrupt_bouns.801").as("brokeBuy24")
                                    .sum("bankrupt_bouns.802").as("brokeBuy25")
                                    .sum("bankrupt_bouns.803").as("brokeBuy26")
                                    .sum("bankrupt_bouns.804").as("brokeBuy27")
                                    .sum("bankrupt_bouns.901").as("brokeBuy28")
                                    .sum("bankrupt_bouns.902").as("brokeBuy29")
                                    .sum("bankrupt_bouns.903").as("brokeBuy30")
                                    .sum("bankrupt_bouns.904").as("brokeBuy31")
                                    .sum("bankrupt_bouns.1001").as("brokeBuy32")
                                    .sum("bankrupt_bouns.1002").as("brokeBuy33")
                                    .sum("bankrupt_bouns.1003").as("brokeBuy34")
                                    .sum("bankrupt_bouns.1004").as("brokeBuy35")
                                    .sum("bankrupt_bouns.1301").as("brokeBuy36")
                                    .sum("bankrupt_bouns.1302").as("brokeBuy37")
                                    .sum("bankrupt_bouns.1303").as("brokeBuy38")
                                    .sum("bankrupt_bouns.1304").as("brokeBuy39")
                                    .sum("bankrupt_bouns.1201").as("brokeBuy40")
                                    .sum("bankrupt_bouns.1202").as("brokeBuy41")
                                    .sum("bankrupt_bouns.1203").as("brokeBuy42")
                                    .sum("bankrupt_bouns.1204").as("brokeBuy43")
                    );
                    AggregationResults<BrokeInfo> ar;
                    if(sysDictDetail.getValue().equals("totalcl")||sysDictDetail.getValue().indexOf("cl_")>0){
                        ar =fiveMongoTemplate.aggregate(aggregation, "channel_data", BrokeInfo.class);
                    }else if(sysDictDetail.getValue().equals("totalapp")||(sysDictDetail.getValue().indexOf("gdmj")==0&&sysDictDetail.getDictSort()!=900&&sysDictDetail.getDictSort()!=910)){
                        ar =ninethMongoTemplate.aggregate(aggregation, "channel_data", BrokeInfo.class);
                    }else {
                        ar = mongoTemplate.aggregate(aggregation, "channel_data", BrokeInfo.class);
                    }
                    List<BrokeInfo> list1 = ar.getMappedResults();
                    if (list1.size() > 0) {
                        brokeInfo = list1.get(0);
                    }
                    brokeInfo.setTheValues(getTheValues(sysDictDetail,gameList,placeList,beginTime,endTime,collectionName));
//                    System.out.println("brokeInfo is = "+brokeInfo);
                    String arrStr="";
                    String[] intResult;
                    for(SysDictDetail sysDictDetail2:gameList){
                        for (SysDictDetail sysDictDetail3:placeList){
                            if(!sysDictDetail2.getValue().equals("5")||!sysDictDetail2.getValue().equals("6")) {
                                criteria = new Criteria();
                                criteria.and("unix_time").gte(beginTime).lt(endTime);
                                criteria.and("gameid").is(Integer.parseInt(sysDictDetail2.getValue()));
                                criteria.and("placeid").is(Integer.parseInt(sysDictDetail3.getValue()));
                                if (!sysDictDetail.getValue().equals("totalcl")) {
                                    if (!sysDictDetail.getValue().equals("total")) {
                                        if (sysDictDetail.getDictSort() != null && sysDictDetail.getDictSort() == 987) {
                                                criteria.and("invite_channel").is(sysDictDetail.getValue());
                                        } else if(sysDictDetail.getDictSort()==900||sysDictDetail.getDictSort()==910){
                                           criteria.and("channel").regex(sysDictDetail.getValue().split("_")[0]);
                                        }else {
                                            criteria.and("channel").is(sysDictDetail.getValue());
                                        }
                                    }
                                }
                                Integer[] s = {500320, 500367, 500369, 500371, 500685, 500690, 500700, 500710, 500321, 500370, 500372, 500377, 500412, 500686, 500691, 500701, 500711
                                        , 500322, 500373, 500378, 500413, 500687, 500692, 500702, 500712, 500323, 500374, 500379, 500430, 500688, 500693, 500703, 500713, 500324, 500375, 500380, 500431, 500689, 500694, 500704, 500714, 500414, 500418, 500432, 500695, 500705, 500715, 500325, 500376, 500381, 500433, 500696, 500706, 500716
                                        , 500326, 500382, 500415, 500697, 500707, 500717, 500327, 500383, 500416, 500698, 500708, 500718, 500328, 500384, 500417, 500699, 500709, 500719,500779,500780,500781,500782,500783,500784,500785,500786,500787,500788,500789,500790,500791
                                ,500792,500793,500794,500795,500796,500797,500798,500799,500800,500801,500802,500803,500804,500805,500806,500807,500808,500809,500810,500811,500812,500813,500814,500815,500816,500817,500818,502228,502229,502230,502231,502232,502233,502234,502235,502236,502237,502238};
                                criteria.and("mall_id").in(s);
                             //   if(sysDictDetail.getDictSort()==910){
                                 //  System.out.println("tiaojian ==============="+new Query().addCriteria(criteria));
                             //   }
                                aggregation = Aggregation.newAggregation(
                                        Aggregation.match(criteria),
                                        Aggregation.group().sum("fee").as("broke"));
                                if(sysDictDetail.getValue().equals("totalcl")||sysDictDetail.getValue().indexOf("cl_")>0){
                                    ar = sixthMongoTemplate.aggregate(aggregation, collectionName, BrokeInfo.class);
                                }else if(sysDictDetail.getValue().equals("totalapp")||(sysDictDetail.getValue().indexOf("gdmj")==0&&sysDictDetail.getDictSort()!=900&&sysDictDetail.getDictSort()!=910)){
                                    ar =tenthMongoTemplate.aggregate(aggregation, collectionName, BrokeInfo.class);
                                }else {
                                    ar =  secondaryMongoTemplate.aggregate(aggregation, collectionName, BrokeInfo.class);
                                }
                                if (ar.getMappedResults().size() > 0) {
                                    arrStr += ar.getMappedResults().get(0).getBroke() + "@";
                                } else {
                                    arrStr += "0@";
                                }
                            }
                        }
                    }
                    intResult=arrStr.split("@");
                    brokeInfo.setActive(Integer.valueOf(intResult[0]));//101
                    brokeInfo.setActive1(Integer.valueOf(intResult[1]));//102
                    brokeInfo.setActive2(Integer.valueOf(intResult[2]));//103
                    brokeInfo.setActive3(Integer.valueOf(intResult[3]));//104
                    brokeInfo.setActive4(Integer.valueOf(intResult[4]));//105
                    brokeInfo.setActive5(Integer.valueOf(intResult[5]));//201
                    brokeInfo.setActive6(Integer.valueOf(intResult[6]));//202
                    brokeInfo.setActive7(Integer.valueOf(intResult[7]));//203
                    brokeInfo.setActive8(Integer.valueOf(intResult[8]));//204
                    brokeInfo.setActive9(Integer.valueOf(intResult[9]));//205
                    brokeInfo.setActive10(Integer.valueOf(intResult[10]));//301
                    brokeInfo.setActive11(Integer.valueOf(intResult[11]));//302
                    brokeInfo.setActive12(Integer.valueOf(intResult[12]));//303
                    brokeInfo.setActive13(Integer.valueOf(intResult[13]));//304
                    brokeInfo.setActive14(Integer.valueOf(intResult[14]));//305
                    brokeInfo.setActive15(Integer.valueOf(intResult[15]));//401
                    brokeInfo.setActive16(Integer.valueOf(intResult[16]));//402
                    brokeInfo.setActive17(Integer.valueOf(intResult[17]));//403
                    brokeInfo.setActive18(Integer.valueOf(intResult[18]));//404
                    brokeInfo.setActive19(Integer.valueOf(intResult[19]));//405
                    brokeInfo.setActive20(Integer.valueOf(intResult[20]));//601
                    brokeInfo.setActive21(Integer.valueOf(intResult[21]));//602
                    brokeInfo.setActive22(Integer.valueOf(intResult[22]));//603
                    brokeInfo.setActive23(Integer.valueOf(intResult[23]));//604
                    brokeInfo.setActive24(Integer.valueOf(intResult[30]));//801
                    brokeInfo.setActive25(Integer.valueOf(intResult[31]));//802
                    brokeInfo.setActive26(Integer.valueOf(intResult[32]));//803
                    brokeInfo.setActive27(Integer.valueOf(intResult[33]));//804
                    brokeInfo.setActive28(Integer.valueOf(intResult[35]));//901
                    brokeInfo.setActive29(Integer.valueOf(intResult[36]));//902
                    brokeInfo.setActive30(Integer.valueOf(intResult[37]));//903
                    brokeInfo.setActive31(Integer.valueOf(intResult[38]));//904
                    brokeInfo.setActive32(Integer.valueOf(intResult[40]));//1001
                    brokeInfo.setActive33(Integer.valueOf(intResult[41]));//1002
                    brokeInfo.setActive34(Integer.valueOf(intResult[42]));//1003
                    brokeInfo.setActive35(Integer.valueOf(intResult[43]));//1004
                    brokeInfo.setActive36(Integer.valueOf(intResult[55]));//1301
                    brokeInfo.setActive37(Integer.valueOf(intResult[56]));//1302
                    brokeInfo.setActive38(Integer.valueOf(intResult[57]));//1303
                    brokeInfo.setActive39(Integer.valueOf(intResult[58]));//1304
                    brokeInfo.setActive40(Integer.valueOf(intResult[50]));//1201
                    brokeInfo.setActive41(Integer.valueOf(intResult[51]));//1202
                    brokeInfo.setActive42(Integer.valueOf(intResult[52]));//1203
                    brokeInfo.setActive43(Integer.valueOf(intResult[53]));//1204
                    brokeInfo.setTime(beginTime.intValue());
                    brokeInfo.setChannel(sysDictDetail.getValue());
                    if (sysDictDetail.getValue().equals("total")||sysDictDetail.getValue().equals("totalcl")||sysDictDetail.getValue().equals("totalapp")) {
                        brokeInfo.setTheFather(null);
                    } else {
                        if (sysDictDetail.getDictSort() != null && sysDictDetail.getDictSort() == 987) {
                            if (sysDictDetail.getValue().equals("qq_share") || sysDictDetail.getValue().equals("h5hzmjxl_qq")) {
                                brokeInfo.setTheFather("h5hzmjxl_qq");
                            } else if(sysDictDetail.getValue().indexOf("gdmj")>-1){
                                brokeInfo.setTheFather("h5gdmjxl_wechat");
                            }else if(sysDictDetail.getValue().indexOf("hcmj")>-1){
                                brokeInfo.setTheFather("h5hcmjxl_wechat");
                            }else {
                                brokeInfo.setTheFather("h5hzmjxl_wechat");
                            }
                        } else if(sysDictDetail.getDictSort()==900){
                            brokeInfo.setTheFather("total");
                        }else if(sysDictDetail.getDictSort()==910){
                            brokeInfo.setTheFather("taotacl");
                        }else if(sysDictDetail.getDictSort()==920){
                            brokeInfo.setTheFather("taotaapp");
                        }else {
                            if(sysDictDetail.getValue().equals("h5zhsmjcl_wechat")){
                                brokeInfo.setTheFather("zsmjxl_total");
                            }else if(sysDictDetail.getValue().indexOf("gdmj")==0){
                                brokeInfo.setTheFather(sysDictDetail.getValue().split("_")[0]+"_app_total");
                            }else {
                                brokeInfo.setTheFather(sysDictDetail.getValue().split("_")[0].replace("h5","")+"_total");
                            }
                        }
                    }
                    QueryWrapper<BrokeInfo> wrapper3 = new QueryWrapper<>();
                    wrapper3.eq("time", beginTime);
                    wrapper3.eq("channel",brokeInfo.getChannel());
                    if(StringUtils.isNotEmpty(brokeInfo.getTheFather())){
                        wrapper3.eq("the_father",brokeInfo.getTheFather());
                    }
                    BrokeInfo brokeInfo1= brokeInfoMapper.selectOne(wrapper3);
                    if(brokeInfo1==null) {
                        brokeInfoMapper.insert(brokeInfo);
                    }else {
                      brokeInfoMapper.update(brokeInfo,wrapper3);
                    }
                    if (sysDictDetail.getDictSort() == null || sysDictDetail.getDictSort() == 900 || sysDictDetail.getDictSort() == 910|| sysDictDetail.getDictSort() == 920) {
                        criteria = new Criteria();
                        criteria.and("unix_time").gte(beginTime).lte(endTime);
                        if (sysDictDetail.getDictSort() != null && (sysDictDetail.getDictSort() == 900 || sysDictDetail.getDictSort() == 910|| sysDictDetail.getDictSort() == 920)) {
                            criteria.and("channel").regex(sysDictDetail.getValue().split("_")[0]);
                        }
                        aggregation = Aggregation.newAggregation(
                                Aggregation.match(criteria),
                                Aggregation.group("user_id").count().as("v1")
                        );
                        AggregationResults<StaticeEntity> ar1;
                        if (sysDictDetail.getValue().equals("totalcl") || sysDictDetail.getValue().indexOf("cl_") > 0) {
                            ar1 = sixthMongoTemplate.aggregate(aggregation, "dw_ppl_game_detail_di", StaticeEntity.class);
                        } else if (sysDictDetail.getValue().equals("totalapp") || (sysDictDetail.getValue().indexOf("gdmj") == 0&&sysDictDetail.getDictSort()!=900&&sysDictDetail.getDictSort()!=910)) {
                            ar1 = tenthMongoTemplate.aggregate(aggregation, "dw_ppl_game_detail_di", StaticeEntity.class);
                        } else {
                            ar1 = secondaryMongoTemplate.aggregate(aggregation, "dw_ppl_game_detail_di", StaticeEntity.class);
                        }

                        List<StaticeEntity> list3 = ar1.getMappedResults();
                        PlayerNumber playerNumber = new PlayerNumber();
                        int time = beginTime.intValue();
                        playerNumber.setTime(time);
                        playerNumber.setChannel(sysDictDetail.getValue());
                        if (list3.size() > 0) {
                            for (StaticeEntity staticeEntity : list3) {
                                if (staticeEntity.getV1() == 1) {
                                    playerNumber.setPlayerNum1(playerNumber.getPlayerNum1() + 1);
                                } else if (staticeEntity.getV1() == 2) {
                                    playerNumber.setPlayerNum2(playerNumber.getPlayerNum2() + 1);
                                } else if (staticeEntity.getV1() == 3) {
                                    playerNumber.setPlayerNum3(playerNumber.getPlayerNum3() + 1);
                                } else if (staticeEntity.getV1() == 4) {
                                    playerNumber.setPlayerNum4(playerNumber.getPlayerNum4() + 1);
                                } else if (staticeEntity.getV1() == 5) {
                                    playerNumber.setPlayerNum5(playerNumber.getPlayerNum5() + 1);
                                } else if (staticeEntity.getV1() == 6) {
                                    playerNumber.setPlayerNum6(playerNumber.getPlayerNum6() + 1);
                                } else if (staticeEntity.getV1() == 7) {
                                    playerNumber.setPlayerNum7(playerNumber.getPlayerNum7() + 1);
                                } else if (staticeEntity.getV1() == 8) {
                                    playerNumber.setPlayerNum8(playerNumber.getPlayerNum8() + 1);
                                } else if (staticeEntity.getV1() == 9) {
                                    playerNumber.setPlayerNum9(playerNumber.getPlayerNum9() + 1);
                                } else if (staticeEntity.getV1() == 10) {
                                    playerNumber.setPlayerNum10(playerNumber.getPlayerNum10() + 1);
                                } else if (staticeEntity.getV1() == 11) {
                                    playerNumber.setPlayerNum11(playerNumber.getPlayerNum11() + 1);
                                } else if (staticeEntity.getV1() == 12) {
                                    playerNumber.setPlayerNum12(playerNumber.getPlayerNum12() + 1);
                                } else if (staticeEntity.getV1() == 13) {
                                    playerNumber.setPlayerNum13(playerNumber.getPlayerNum13() + 1);
                                } else if (staticeEntity.getV1() == 14) {
                                    playerNumber.setPlayerNum14(playerNumber.getPlayerNum14() + 1);
                                } else if (staticeEntity.getV1() == 15) {
                                    playerNumber.setPlayerNum15(playerNumber.getPlayerNum15() + 1);
                                } else if (staticeEntity.getV1() > 15 && staticeEntity.getV1() < 101) {
                                    playerNumber.setPlayerNum16(playerNumber.getPlayerNum16() + 1);
                                } else if (staticeEntity.getV1() > 100) {
                                    playerNumber.setPlayerNum17(playerNumber.getPlayerNum17() + 1);
                                }
                            }
                        }
                        criteria = new Criteria();
                        criteria.and("last_time").gte(beginTime).lte(endTime);
                        if (sysDictDetail.getDictSort() != null && (sysDictDetail.getDictSort() == 900 || sysDictDetail.getDictSort() == 910|| sysDictDetail.getDictSort() == 920)) {
                            criteria.and("channel").regex(sysDictDetail.getValue().split("_")[0]);
                        }
                        long count = 0l;
                        if (sysDictDetail.getValue().equals("totalcl") || sysDictDetail.getValue().indexOf("cl_") > 0) {
                            count = fiveMongoTemplate.count(new Query().addCriteria(criteria), "user");
                        }else if (sysDictDetail.getValue().equals("totalapp") || (sysDictDetail.getValue().indexOf("gdmj")==0&&sysDictDetail.getDictSort()!=900&&sysDictDetail.getDictSort()!=910)) {
                            count = ninethMongoTemplate.count(new Query().addCriteria(criteria), "user");
                        } else {
                            count = mongoTemplate.count(new Query().addCriteria(criteria), "user");
                        }
                        playerNumber.setActNum((int) count);
                        QueryWrapper<PlayerNumber> wrapper4 = new QueryWrapper<>();
                        wrapper4.eq("time", playerNumber.getTime());
                        wrapper4.eq("channel", sysDictDetail.getValue());
                        PlayerNumber playerNumber1 = playerNumberMapper.selectOne(wrapper4);
                        if (playerNumber1 == null) {
                            playerNumberMapper.insert(playerNumber);
                        } else {
                            playerNumberMapper.update(playerNumber, wrapper4);
                        }
                    }
                }
            }
        }
    private  String getTheValues(SysDictDetail channel,List<SysDictDetail>  roomTypeList,List<SysDictDetail>  roomLeveList,Long beginTime,Long endTime,String collectionName){
            String brokeValue="";
            for(SysDictDetail sysDictDetail:roomTypeList){
                for(SysDictDetail sysDictDetail1:roomLeveList) {
                    brokeValue += sysDictDetail.getValue() + "0"+sysDictDetail1.getValue()+ ":{";
                    brokeValue += getValues(channel.getValue(), beginTime, sysDictDetail.getValue() + "0"+sysDictDetail1.getValue());
                    brokeValue += getMoneys(channel, beginTime, endTime, Integer.parseInt(sysDictDetail.getValue()), Integer.parseInt(sysDictDetail1.getValue()), collectionName) + "},";
                }
            }
            brokeValue=  "{" + brokeValue.substring(0, brokeValue.length() - 1) + "}";
            return brokeValue;
        }

    private String getMoneys(SysDictDetail channel,Long beginTime,Long endTime,Integer  roomType,Integer roomLevel,String collectionName){
           String arrStr="";
            Criteria criteria = new Criteria();
            criteria.and("unix_time").gte(beginTime).lt(endTime);
            criteria.and("gameid").is(roomType);
            criteria.and("placeid").is(roomLevel);
            if (channel.getDictSort()!=999) {
                    if (channel.getDictSort() != null && channel.getDictSort() == 987) {
                        criteria.and("invite_channel").is(channel.getValue());
                    } else if(channel.getDictSort()==900||channel.getDictSort()==910||channel.getDictSort()==920){
                        criteria.and("channel").regex(channel.getValue().split("_")[0]);
                    }else {
                        criteria.and("channel").is(channel.getValue());
                    }

            }
            Integer[] s = {500320, 500367, 500369, 500371, 500685, 500690, 500700, 500710, 500321, 500370, 500372, 500377, 500412, 500686, 500691, 500701, 500711
                    , 500322, 500373, 500378, 500413, 500687, 500692, 500702, 500712, 500323, 500374, 500379, 500430, 500688, 500693, 500703, 500713, 500324, 500375, 500380, 500431, 500689, 500694, 500704, 500714, 500414, 500418, 500432, 500695, 500705, 500715, 500325, 500376, 500381, 500433, 500696, 500706, 500716
                    , 500326, 500382, 500415, 500697, 500707, 500717, 500327, 500383, 500416, 500698, 500708, 500718, 500328, 500384, 500417, 500699, 500709, 500719,500779,500780,500781,500782,500783,500784,500785,500786,500787,500788,500789,500790,500791
                    ,500792,500793,500794,500795,500796,500797,500798,500799,500800,500801,500802,500803,500804,500805,500806,500807,500808,500809,500810,500811,500812,500813,500814,500815,500816,500817,500818,502228,502229,502230,502231,502232,502233,502234,502235,502236,502237,502238};
            criteria.and("mall_id").in(s);
            AggregationResults<BrokeInfo> ar;
            Aggregation aggregation = Aggregation.newAggregation(
                    Aggregation.match(criteria),
                    Aggregation.group().sum("fee").as("broke"));
            if(channel.getValue().equals("totalcl")||channel.getValue().indexOf("cl_")>0){
                ar = sixthMongoTemplate.aggregate(aggregation, collectionName, BrokeInfo.class);
            }else {
                ar =  secondaryMongoTemplate.aggregate(aggregation, collectionName, BrokeInfo.class);
            }
            if (ar.getMappedResults().size() > 0) {
                arrStr += ",money:"+ ar.getMappedResults().get(0).getBroke() ;
            } else {
                arrStr += ",money:0";
            }
            return arrStr;
     }
    private String getValues(String channel,Long beginTime,String roomLevel){
            Criteria criteria=new Criteria();
            criteria.and("day").is(beginTime);
            if (channel.equals("total")||channel.equals("totalcl")){}else  {
                if(channel.indexOf("_total")>0) {
                    criteria.and("channel").regex(channel.split("_")[0]);
                }
                else {
                    criteria.and("channel").is(channel);
                }
            }
            Aggregation aggregation = Aggregation.newAggregation(
                    Aggregation.match(criteria),
                    Aggregation.group().sum("brokes."+roomLevel).as("broke")
                            .sum("bankrupt_bouns."+roomLevel).as("brokeBuy")
                );
            AggregationResults<BrokeInfo> ar;
            if(channel.equals("totalcl")||channel.indexOf("cl_")>0){
                ar =fiveMongoTemplate.aggregate(aggregation, "channel_data", BrokeInfo.class);
            }else {
                ar = mongoTemplate.aggregate(aggregation, "channel_data", BrokeInfo.class);
            }
            List<BrokeInfo> list1 = ar.getMappedResults();
            if (list1.size() > 0) {
                return "broke:"+list1.get(0).getBroke()+",brokeBuy:"+list1.get(0).getBrokeBuy();
            }else {
                return "broke:0,brokeBuy:0";
            }
        }


    public void roomsByTotal() {
        log.info("运营数据任务roomstotal：开始执行=======================");
        String collectionName = "tally_rec_";
        String gameRoundName = "game_round_rec_";
        String gameName="login_game_rec_";
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM");
        Long beginTime = DateUtil.getDayBegin().getTime() / 1000;
        Long nowTime=new Date().getTime()/1000;
        String dateStr = ft.format(new Date()).replace("-", "").trim();
        if(nowTime==beginTime){
            beginTime=DateUtil.getBeginDayOfYesterday().getTime()/1000;
            if(!DateUtil.timeStamp2Date(beginTime+"","yyyyMM").equals(DateUtil.timeStamp2Date(nowTime+"","yyyyMM"))){
                dateStr =DateUtil.timeStamp2Date(beginTime+"","yyyyMM");
            }
        }
        Long endTime = beginTime+86400;

        collectionName = collectionName + dateStr;
        gameRoundName = gameRoundName + dateStr;
        gameName = gameName + dateStr;
        Criteria criteria;
        QueryWrapper<SysDictDetail> wrapper1 = new QueryWrapper<>();
        wrapper1.eq("dict_id", 21);
        List<SysDictDetail> list1 = sysDictDetailMapper.selectList(wrapper1);
        wrapper1 = new QueryWrapper<>();
        wrapper1.eq("dict_id", 22);
        List<SysDictDetail> list2 = sysDictDetailMapper.selectList(wrapper1);
        String str = "";
        String theValue="";
        Aggregation aggregation;
        AggregationResults<TallyRecEntity> ar;
        List<TallyRecEntity> list;
        QueryWrapper<SysDictDetail> wrapper = new QueryWrapper<>();
        wrapper.eq("dict_id", 16);
        wrapper.le("dict_sort", 988);
        wrapper.orderByDesc("dict_sort");
        List<SysDictDetail> list5 = new ArrayList<>();
        SysDictDetail sysDictDetail4 = new SysDictDetail();
        sysDictDetail4.setValue("total");
        list5.add(sysDictDetail4);
        sysDictDetail4 = new SysDictDetail();
        sysDictDetail4.setValue("totalcl");
        list5.add(sysDictDetail4);
        sysDictDetail4 = new SysDictDetail();
        sysDictDetail4.setValue("totalapp");
        list5.add(sysDictDetail4);
        if (list5.size() > 0) {
            for (SysDictDetail sysDictDetail3 : list5) {
                str = "";
                theValue = "";
                RoomsUserInfo roomsUserInfo = new RoomsUserInfo();
                for (SysDictDetail sysDictDetail : list1) {
                    for (SysDictDetail sysDictDetail2 : list2) {
                        theValue += "\"a" + sysDictDetail.getValue() + "0" + sysDictDetail2.getValue() + "\":{";
                        criteria = new Criteria();
                        criteria.and("unix_time").gte(beginTime).lte(endTime);
                        criteria.and("gameType").is(Integer.parseInt(sysDictDetail.getValue() + "0" + sysDictDetail2.getValue()));
                        aggregation = Aggregation.newAggregation(
                                Aggregation.match(criteria),
                                Aggregation.group("id").count().as("ioType"),
                                Aggregation.group("id").count().as("ioType")
                        );
                        if (sysDictDetail3.getValue().equals("totalcl")) {
                            ar = sixthMongoTemplate.aggregate(aggregation, gameName, TallyRecEntity.class);
                        }else if (sysDictDetail3.getValue().equals("totalapp")) {
                            ar = tenthMongoTemplate.aggregate(aggregation, gameName, TallyRecEntity.class);
                        } else {
                            ar = secondaryMongoTemplate.aggregate(aggregation, gameName, TallyRecEntity.class);
                        }
                        list = ar.getMappedResults();
                        if (list.size() > 0) {
                            str = str + "@"+sysDictDetail.getValue() + "0" + sysDictDetail2.getValue() + "/" + list.get(0).getIoType();
                            theValue += "\"active\":" + list.get(0).getIoType() + ",";
                        } else {
                            str = str + "@"+sysDictDetail.getValue() + "0" + sysDictDetail2.getValue() + "/0";
                            theValue += "\"active\":0,";
                        }
                        aggregation = Aggregation.newAggregation(
                                Aggregation.match(criteria),
                                Aggregation.group("roomid").count().as("ioType"),
                                Aggregation.group("roomid").count().as("ioType")
                        );
                        if (sysDictDetail3.getValue().equals("totalcl")) {
                            ar = sixthMongoTemplate.aggregate(aggregation, gameName, TallyRecEntity.class);
                        }else if (sysDictDetail3.getValue().equals("totalapp")) {
                            ar = tenthMongoTemplate.aggregate(aggregation, gameName, TallyRecEntity.class);
                        } else {
                            ar = secondaryMongoTemplate.aggregate(aggregation, gameName, TallyRecEntity.class);
                        }
                        list = ar.getMappedResults();
                        if (list.size() > 0) {
                            str = str + "/" + list.get(0).getIoType();
                            theValue += "\"number\":" + list.get(0).getIoType() + ",";
                            roomsUserInfo.setNumber(roomsUserInfo.getNumber() + list.get(0).getIoType());
                        } else {
                            str = str + "/0";
                            theValue += "\"number\":0,";
                        }
                        criteria = new Criteria();
                        criteria.and("time").gte(nowTime-7200).lte(nowTime);
                        criteria.and("gameid").is(Integer.parseInt(sysDictDetail.getValue()));
                        criteria.and("placeid").is(Integer.parseInt(sysDictDetail2.getValue()));
                        criteria.and("is_robot").is(true);
                       aggregation = Aggregation.newAggregation(
                          Aggregation.match(criteria),
                         Aggregation.group().sum("num").as("num")
                       );
                       if (sysDictDetail3.getValue().equals("totalcl")) {
                           ar = sixthMongoTemplate.aggregate(aggregation, collectionName, TallyRecEntity.class);
                       }else if (sysDictDetail3.getValue().equals("totalapp")) {
                           ar = tenthMongoTemplate.aggregate(aggregation, collectionName, TallyRecEntity.class);
                       }  else {
                          ar = secondaryMongoTemplate.aggregate(aggregation, collectionName, TallyRecEntity.class);
                       }
                       list = ar.getMappedResults();
                       if (list.size() > 0) {
                           if(Double.isNaN(list.get(0).getNum())){
                               str = str + "/0";
                               theValue += "\"money\":0,";
                           }
                           else {
                                str = str + "/" + list.get(0).getNum();
                                theValue += "\"money\":" + list.get(0).getNum() + ",";
                                if(roomsUserInfo.getMoney()==null){
                                    roomsUserInfo.setMoney(list.get(0).getNum());
                                 }else {
                                    roomsUserInfo.setMoney(roomsUserInfo.getMoney() + list.get(0).getNum());
                                 }
                           }
                       } else {
                          str = str + "/0";
                         theValue += "\"money\":0,";
                       }
                            criteria = new Criteria();
                            criteria.and("unix_time").gte(beginTime).lte(endTime);
                            criteria.and("gameid").is(Integer.parseInt(sysDictDetail.getValue()));
                            criteria.and("placeid").is(Integer.parseInt(sysDictDetail2.getValue()));
                            aggregation = Aggregation.newAggregation(
                                    Aggregation.match(criteria),
                                    Aggregation.group().avg("usetime").as("unix_time")
                            );
                            if (sysDictDetail3.getValue().equals("totalcl") || sysDictDetail3.getValue().indexOf("cl_") > 0) {
                                ar = sixthMongoTemplate.aggregate(aggregation, gameRoundName, TallyRecEntity.class);
                            } else if (sysDictDetail3.getValue().equals("totalapp")) {
                                ar = tenthMongoTemplate.aggregate(aggregation, gameRoundName, TallyRecEntity.class);
                            }else {
                                ar = secondaryMongoTemplate.aggregate(aggregation, gameRoundName, TallyRecEntity.class);
                            }
                            list = ar.getMappedResults();
                            if (list.size() > 0) {
                                str = str + "/" + list.get(0).getUnix_time();
                                theValue += "\"avgTime\":" + list.get(0).getUnix_time() + "},";
                                roomsUserInfo.setAvgTime((int) list.get(0).getUnix_time());

                            } else {
                                str = str + "/0";
                                theValue += "\"avgTime\":0},";
                            }
                    }
                }

                theValue = "{" + theValue.substring(0, theValue.length() - 1) + "}";
                String[] strArray = str.split("@");
                // System.out.println(str);
                roomsUserInfo.setTheValue(theValue);
                roomsUserInfo.setTheFather(null);
                criteria = new Criteria();
                criteria.and("unix_time").gte(beginTime).lte(endTime);
                aggregation = Aggregation.newAggregation(
                        Aggregation.match(criteria),
                        Aggregation.group("id").count().as("ioType"),
                        Aggregation.group("id").count().as("ioType")
                );
                if (sysDictDetail3.getValue().equals("totalcl")) {
                    ar = sixthMongoTemplate.aggregate(aggregation, gameName, TallyRecEntity.class);
                } else if (sysDictDetail3.getValue().equals("totalapp")) {
                    ar = tenthMongoTemplate.aggregate(aggregation, gameName, TallyRecEntity.class);
                } else {
                    ar = secondaryMongoTemplate.aggregate(aggregation, gameName, TallyRecEntity.class);
                }
                list = ar.getMappedResults();
                if (list.size() > 0) {
                    roomsUserInfo.setActive(list.get(0).getIoType());
                }
                roomsUserInfo.setChannel(sysDictDetail3.getValue());
                roomsUserInfo.setCreateTime(beginTime);
                QueryWrapper<RoomsUserInfo> wrapper3 = new QueryWrapper<>();
                wrapper3.eq("create_time", beginTime);
                wrapper3.eq("channel", roomsUserInfo.getChannel());
                RoomsUserInfo roomsUserInfo1 = roomsUserInfoMapper.selectOne(wrapper3);
                if (roomsUserInfo1 == null) {
                    roomsUserInfo1 = new RoomsUserInfo();
                }
                if (roomsUserInfo1.getTheValue() != null && (roomsUserInfo1.getChannel().equals("total") || roomsUserInfo1.getChannel().equals("totalcl"))) {
                    JSONObject jsonObject = JSONObject.parseObject(roomsUserInfo1.getTheValue());
                    JSONObject jsonObject1 = JSONObject.parseObject(roomsUserInfo.getTheValue());
                    Set<String> set = jsonObject.keySet();
                    for (int i = 0; i < jsonObject.size(); i++) {
                        if (jsonObject.getJSONObject(set.toArray()[i].toString()) != null) {
                            try {
//                                System.out.println("dddddddddd 11111111111111");
//                                System.out.println(jsonObject1.getJSONObject(set.toArray()[i].toString()).getString("money"));
//                                System.out.println(jsonObject.getJSONObject(set.toArray()[i].toString()).getString("money"));
                                Double j = Double.valueOf(jsonObject1.getJSONObject(set.toArray()[i].toString()).getString("money")) + Double.valueOf(jsonObject.getJSONObject(set.toArray()[i].toString()).getString("money"));
                                jsonObject1.getJSONObject(set.toArray()[i].toString()).put("money", j);
                            }catch (Exception e){}
                        }
                    }
                    roomsUserInfo.setTheValue(jsonObject1.toJSONString());
                }
                for (int j = 1; j < strArray.length; j++) {
                    int res=Integer.parseInt(strArray[j].split("/")[0]);
                 //   System.out.println("straryay is============"+strArray[j]);
                    if (res==101) {
                        roomsUserInfo.setActive1(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber1(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney1(roomsUserInfo1.getMoney1() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime1(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res==102) {
                        roomsUserInfo.setActive2(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber2(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney2(roomsUserInfo1.getMoney2() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime2(Integer.valueOf(strArray[j].split("/")[4]));
                    } else  if (res==103) {
                        roomsUserInfo.setActive3(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber3(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney3(roomsUserInfo1.getMoney3() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime3(Integer.valueOf(strArray[j].split("/")[4]));
                    } else  if (res==104) {
                        roomsUserInfo.setActive4(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber4(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney4(roomsUserInfo1.getMoney4() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime4(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res==105) {
                        roomsUserInfo.setActive5(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber5(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney5(roomsUserInfo1.getMoney5() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime5(Integer.valueOf(strArray[j].split("/")[4]));
                    } else  if (res==201) {
                        roomsUserInfo.setActive6(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber6(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney6(roomsUserInfo1.getMoney6() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime6(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res==202) {
                        roomsUserInfo.setActive7(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber7(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney7(roomsUserInfo1.getMoney7() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime7(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res==203) {
                        roomsUserInfo.setActive8(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber8(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney8(roomsUserInfo1.getMoney8() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime8(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res==204) {
                        roomsUserInfo.setActive9(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber9(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney9(roomsUserInfo1.getMoney9() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime9(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res==205) {
                        roomsUserInfo.setActive10(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber10(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney10(roomsUserInfo1.getMoney10() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime10(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res==301) {
                        roomsUserInfo.setActive11(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber11(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney11(roomsUserInfo1.getMoney11() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime11(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res==302) {
                        roomsUserInfo.setActive12(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber12(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney12(roomsUserInfo1.getMoney12() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime12(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res==303) {
                        roomsUserInfo.setActive13(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber13(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney13(roomsUserInfo1.getMoney13() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime13(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res==304) {
                        roomsUserInfo.setActive14(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber14(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney14(roomsUserInfo1.getMoney14() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime14(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res==305) {
                        roomsUserInfo.setActive15(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber15(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney15(roomsUserInfo1.getMoney15() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime15(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res==401) {
                        roomsUserInfo.setActive16(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber16(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney16(roomsUserInfo1.getMoney16() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime16(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res==402) {
                        roomsUserInfo.setActive17(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber17(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney17(roomsUserInfo1.getMoney17() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime17(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res==403) {
                        roomsUserInfo.setActive18(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber18(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney18(roomsUserInfo1.getMoney18() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime18(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res==404) {
                        roomsUserInfo.setActive19(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber19(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney19(roomsUserInfo1.getMoney19() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime19(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res==601) {
                        roomsUserInfo.setActive20(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber20(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney20(roomsUserInfo1.getMoney20() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime20(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res==602) {
                        roomsUserInfo.setActive21(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber21(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney21(roomsUserInfo1.getMoney21() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime21(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res==603) {
                        roomsUserInfo.setActive22(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber22(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney22(roomsUserInfo1.getMoney22() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime22(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res==604) {
                        roomsUserInfo.setActive23(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber23(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney23(roomsUserInfo1.getMoney23() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime23(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res == 701) {
                        roomsUserInfo.setActive24(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber24(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney24(roomsUserInfo1.getMoney24() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime24(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res == 702) {
                        roomsUserInfo.setActive25(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber25(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney25(roomsUserInfo1.getMoney25() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime25(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res == 703) {
                        roomsUserInfo.setActive26(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber26(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney26(roomsUserInfo1.getMoney26() + Long.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime26(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res == 704) {
                        roomsUserInfo.setActive27(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber27(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney27(roomsUserInfo1.getMoney27() + Long.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime27(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res == 801) {
                        roomsUserInfo.setActive28(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber28(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney28(roomsUserInfo1.getMoney28() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime28(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res == 802) {
                        roomsUserInfo.setActive29(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber29(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney29(roomsUserInfo1.getMoney29() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime29(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res == 803) {
                        roomsUserInfo.setActive30(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber30(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney30(roomsUserInfo1.getMoney30() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime30(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res == 804) {
                        roomsUserInfo.setActive31(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber31(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney31(roomsUserInfo1.getMoney31() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime31(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res == 805) {
                        roomsUserInfo.setActive32(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber32(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney32(roomsUserInfo1.getMoney32() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime32(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res == 901) {
                        roomsUserInfo.setActive33(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber33(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney33(roomsUserInfo1.getMoney33() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime33(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res == 902) {
                        roomsUserInfo.setActive34(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber34(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney34(roomsUserInfo1.getMoney34() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime34(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res == 903) {
                        roomsUserInfo.setActive35(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber35(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney35(roomsUserInfo1.getMoney35() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime35(Integer.valueOf(strArray[j].split("/")[4]));
                    } else if (res == 904) {
                        roomsUserInfo.setActive36(Integer.parseInt(strArray[j].split("/")[1]));
                        roomsUserInfo.setNumber36(Integer.parseInt(strArray[j].split("/")[2]));
                        roomsUserInfo.setMoney36(roomsUserInfo1.getMoney36() + Double.valueOf(strArray[j].split("/")[3]));
                        roomsUserInfo.setAvgTime36(Integer.valueOf(strArray[j].split("/")[4]));
                    }
                }
                if (roomsUserInfo1.getId() == null) {
                    roomsUserInfoMapper.insert(roomsUserInfo);
                } else {
                    roomsUserInfoMapper.update(roomsUserInfo, wrapper3);
                }
            }
        }
        log.info("运营数据任务roomstotal：完成执行=======================");
    }
}


